package oj0529.oj0529_03;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;

public class Main {
    static class Point{
        int x;
        int y;
        int step;

        public Point(int x, int y, int step) {
            this.x = x;
            this.y = y;
            this.step = step;
        }
    }
    //定义走的八个方向
    private static int[][] dirs = {
            {-2,-1},{-1,-2},{1,-2},{2,-1},{-2,1},{-1,2},{1,2},{2,1}
    };

    private static boolean isOk(int x, int y){
        return x>=1 && x<=8 && y>=1 && y<=8;
    }

    private static  int BFS(int a,int b,int c,int d){
        Queue<Point> queue = new LinkedList<>();
        boolean[][] visited = new boolean[9][9];
        queue.add(new Point(a,b,0));
        visited[a][b] = true;

        while (!queue.isEmpty()) {
            Point point = queue.poll();
            if (point.x == c && point.y == d) return point.step;

            for (int i = 0; i < 8; i++) {
                int nx = point.x+dirs[i][0];     //行变化值
                int ny = point.y+dirs[i][1];     //列变化值
                if (isOk(nx,ny) && !visited[nx][ny]){
                    queue.add(new Point(nx,ny, point.step+1));
                    visited[nx][ny] = true;
                }
            }
        }
        return -1;
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int a = sc.nextInt();   //开始x
        int b = sc.nextInt();   //开始y
        int c = sc.nextInt();   //结束x
        int d = sc.nextInt();   //结束y
        if (!isOk(a,b) || !isOk(c,d)){
            System.out.println(-1);
            return;
        }
        int count = BFS(a,b,c,d);
        System.out.println(count);
        sc.close();

    }
}
